package com.shuzijun.leetcode.editor.cn;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PairsWithSumLcci{
    public static void main(String[] args) {
         Solution solution = new PairsWithSumLcci().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public List<List<Integer>> pairSums(int[] nums, int target) {
        ArrayList<List<Integer>> results = new ArrayList<>();
        if (nums.length == 0) return results;
        Arrays.sort(nums);
        int i = 0;
        int j = nums.length-1;
        while (i < j){
            if (nums[i]+nums[j] == target){
                ArrayList<Integer> result = new ArrayList<>();
                result.add(nums[i] );
                result.add(nums[j] );
                results.add(result);
                i++;
                j--;
            } else if (nums[i] + nums[j] < target) {
                i++;
            }else {
                j--;
            }
        }
        return results;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}